package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Resources;

/**
 * 
 * @author 
 *
 */
@DAO
public interface ResourcesDAO{
	
	@SQL("SELECT * FROM Resources WHERE 1=1  AND title=:t.title, AND category=:t.category, AND abstractInfor=:t.abstractInfor, AND carouselImage=:t.carouselImage, AND content=:t.content, AND author=:t.author, AND releaseState=:t.releaseState, AND releaseAT=:t.releaseAT, AND deleteFlag=:t.deleteFlag, AND createUser=:t.createUser, AND createAT=:t.createAT, AND updateUser=:t.updateUser, AND updateAT=:t.updateAT, ORDER BY updateAT DESC LIMIT :t.start,:t.end ")
    List<Resources> query(@SQLParam("t") Resources Resources);
    
    @SQL("select * from Resources where id=:1")
    Resources queryById(int id);
    
    @SQL("INSERT INTO Resources (title,category,abstractInfor,carouselImage,content,author,releaseState,releaseAT,deleteFlag,createUser,createAT,updateUser,updateAT,website,digitalNewspaper) VALUES (:t.title,:t.category,:t.abstractInfor,:t.carouselImage,:t.content,:t.author,:t.releaseState,:t.releaseAT,:t.deleteFlag,:t.createUser,:t.createAT,:t.updateUser,:t.updateAT,:t.website,:t.digitalNewspaper)")
    void create(@SQLParam("t") Resources Resources);
	
	@SQL("UPDATE Resources SET title=:t.title,category=:t.category,abstractInfor=:t.abstractInfor,carouselImage=:t.carouselImage,content=:t.content,author=:t.author,updateUser=:t.updateUser,updateAT=NOW(),website=:t.website,digitalNewspaper=:t.digitalNewspaper WHERE id=:t.id")
    void update(@SQLParam("t") Resources Resources);
    
    @SQL("UPDATE Resources SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("select id,title,category,abstractInfor,author,releaseState,date_format(releaseAT,'%Y-%m-%d %H:%i:%s') as releaseAT from Resources where deleteFlag=1  #if(:t.title != ''){  and title like '%##(:t.title)%' }  #if(:t.author != ''){  and author like '%##(:t.author)%' }  #if(:t.releaseState > -1){  and releaseState = :t.releaseState }  #if(:t.category!=''){  and category = :t.category }  #if(:2 != ''){  and releaseAT > date_format('##(:2)','%Y-%m-%d %H:%i:%s') and releaseAT is not null } #if(:3 != ''){  and releaseAT < date_format('##(:3)','%Y-%m-%d %H:%i:%s') and releaseAT is not null }  order by updateAT desc limit :t.start, :t.length")
    List<Resources> queryConditional(@SQLParam("t")Resources t, @SQLParam("beginDate")String beginDate, @SQLParam("endDate")String endDate);
    
    @SQL("select count(1) from Resources where deleteFlag=1  #if(:t.title != ''){  and title like '%##(:t.title)%' }  #if(:t.author != ''){  and author like '%##(:t.author)%' }  #if(:t.releaseState > -1){  and releaseState = :t.releaseState }  #if(:t.category!=''){  and category = :t.category }  #if(:2 != ''){  and releaseAT > date_format('##(:2)','%Y-%m-%d %H:%i:%s') and releaseAT is not null } #if(:3 != ''){  and releaseAT < date_format('##(:3)','%Y-%m-%d %H:%i:%s') and releaseAT is not null } ")
    int querySize(@SQLParam("t")Resources t, @SQLParam("beginDate")String beginDate, @SQLParam("endDate")String endDate);
}